package com.bwei.like.mynewstop.adapater;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bwei.like.mynewstop.R;
import com.bwei.like.mynewstop.app.MyApplication;
import com.bwei.like.mynewstop.base.MyBaseAdapater;
import com.bwei.like.mynewstop.utils.CommonUtils;
import com.bwei.like.mynewstop.utils.TitileUtils;

import java.util.ArrayList;

/**
 * Created by LiKe on 2016/11/10.
 */
public class MyChnanelAdapater extends MyBaseAdapater<String> {
    public MyChnanelAdapater(ArrayList arrayList, Context context) {
        super(arrayList, context);
    }

    @Override
    public View initView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = CommonUtils.inflter(R.layout.my_chnanel);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        viewHolder.myGridchnaneltext.setText(TitileUtils.myChannel.get(position).substring(0,TitileUtils.myChannel.get(position).indexOf(":")));
        if (MyApplication.showChnanelLongListener){
            if (position!=0)
            viewHolder.myGriddeleteimage.setVisibility(View.VISIBLE);
        }else {
            viewHolder.myGriddeleteimage.setVisibility(View.GONE);
        }
        return convertView;
    }

    public class ViewHolder {
        public final TextView myGridchnaneltext;
        public final ImageView myGriddeleteimage;
        public final View root;

        public ViewHolder(View root) {
            myGridchnaneltext = (TextView) root.findViewById(R.id.myGrid_chnanel_text);
            myGriddeleteimage = (ImageView) root.findViewById(R.id.myGrid_delete_image);
            this.root = root;
        }
    }
}
